#!/bin/bash
use_pbc_runner=$1
extra_flags=$2
echo "_______________extra_flags for hermes tests: ${extra_flags}"
export TZ="UTC"
set -e
v8_path=$(realpath $(dirname ${BASH_SOURCE[0]})/..)

host=`uname -a`
arch="x64"
if [[ ${host} == *"aarch64"* ]]; then
  arch="arm64"
fi

bash $v8_path/CI/build_dcheck_d8.sh
if [[ ${use_pbc_runner} == true ]]; then
  rm $v8_path/pbc-test -r
  mkdir -p $v8_path/pbc-test
  bash $v8_path/CI/transform_to_pbc.sh -f $v8_path/CI/white_list.txt $v8_path/pbc-test --dcheck
  bash $v8_path/CI/test_pbc.sh -d $v8_path/pbc-test --extra-flags "${extra_flags}"
else
  bash $v8_path/CI/generate_js_result.sh -j $v8_path/third_party/hermes/hermes/test/hermes --d8-path $v8_path/out/${arch}.release-check/d8
  cat $v8_path/CI/white_list.txt | xargs python3 ./aot_test.py --enable-run-pbc --arch $arch --extra-flags="--verify-heap --verify-simplified-lowering --stress-ic --stress-gc-during-compilation ${extra_flags} " --silent --dcheck -i
fi
